<?php

use think\facade\Route;
use think\facade\Config;
use think\Response;
use app\api\middleware\LoginMiddleware;
use app\api\middleware\UserVisitLog;

/**
 * 无需校验的接口
 */
Route::group(function () {
    //账号登录
    Route::post('login', 'Login/login');
    //账号注册
    Route::post('register', 'Login/register');
    //微信公众号跳转url
    Route::post('getWxOaCodeUrl', 'Login/getWxOaCodeUrl');
    //微信公众号登录
    Route::post('wxOaLogin', 'Login/wxOaLogin');
    //获取微信扫码登录二维码
    Route::post('getWxOpScanCodeUrl', 'Login/getWxOpScanCodeUrl');
    //微信扫码登录
    Route::post('wxScanLogin', 'Login/wxScanLogin');
    //微信小程序登录
    Route::post('wxApLogin', 'Login/wxApLogin');
    //发送验证码
    Route::post('sendSmsCode', 'Sms/sendSmsCode');
    //获取配置
    Route::get('getConfig', 'Index/getConfig');
    //获取微信jssdk配置
    Route::get('getWxJsConfig', 'Index/getWxJsConfig');
    //忘记密码
    Route::post('forgetPassword', 'Login/forgetPassword');
})->middleware([
    UserVisitLog::class
]);

Route::post('logout', 'Login/logout')->middleware([
    LoginMiddleware::class,
    UserVisitLog::class
]);

/**
 * miss 路由
 */
Route::miss(function () {
    if (app()->request->isOptions()) {
        $header = Config::get('cookie.header');
        $header['Access-Control-Allow-Origin'] = app()->request->header('origin');
        return Response::create('ok')->code(200)->header($header);
    } else
        return Response::create()->code(404);
});